<script id="imgItem" type="text/template">
    <div class="file-item" id="<% d.id %>">
        <div class="thumbnail">
            <div class="file-panel">
                <i class="del-icon">移除</i>
            </div>
            <input type="hidden" class="imgs" name="img_<% d.id %>" value="<% d.url %>" />
            <img alt="" class="project-list-item-icon" src="<% d.absUrl %>"/>
        </div>
    </div>
</script>
<script>
    var __uploadUrl = '/file/attachment.do';

    layui.use(['upload', 'element', 'layer','laytpl'], function () {
        var $ = layui.jquery
            ,upload = layui.upload
            ,element = layui.element
            ,layer = layui.layer
            ,laytpl = layui.laytpl;
        laytpl.config({
            open: '<%',
            close: '%>'
        });
        $("#uploadList").on('click','i.del-icon',function(e){
            e.preventDefault();
            console.log('click')
            $(e.currentTarget).parents('.file-item').remove();
        })
        //多图片上传
        upload.render({
            elem: '#uploadBtn'
            ,url: __uploadUrl //此处配置你自己的上传接口即可
            ,multiple: true
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                // obj.preview(function(index, file, result){
                //     $('#uploadList').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
                // });
            }
            ,done: function(res){
                //上传完毕
                console.log(res)
                if(res.code==0){
                    layer.msg("上传成功！");
                    //$('#uploadList').append('<img src="'+ __base.domain+res.data.url +'" alt="'+ res.data.name +'" class="layui-upload-img">')
                    res.data.absUrl = __base.domain+res.data.url;
                    laytpl($("#imgItem").html()).render(res.data, function(html){
                        $('#uploadList').append(html);
                    });
                }else{
                    layer.alert(res.msg);
                }
            }
        });

        //表单初始赋值
        $(".select").click(function(e){
            e.preventDefault();
            var data = [];
            $('#uploadList').find('.imgs').each(function(index,ele){
                data.push($(ele).val());
            });
            parent.appendImg(data);
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });
        $(".cancel").click(function(e){
            e.preventDefault();

            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });


    });
</script>